home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / LAYOUTCO.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  11KB  |  395 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.3  $
  6. //
  7. // Definition of class TLayoutConstraint.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_LAYOUTCO_H)
  10. #define OWL_LAYOUTCO_H
  11.  
  12. #if !defined(OWL_DEFS_H)
  13. # include <owl/defs.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. // Generic definitions/compiler options (eg. alignment) preceeding the 
  21. // definition of classes
  22. #include <services/preclass.h>
  23.  
  24. class _OWLCLASS TWindow;
  25.  
  26. //
  27. // Use to represent the parent in layout metrics
  28. //
  29. #define lmParent    0
  30.  
  31. enum TEdge {lmLeft, lmTop, lmRight, lmBottom, lmCenter};
  32.  
  33. enum TWidthHeight {lmWidth = lmCenter + 1, lmHeight};
  34.  
  35. enum TMeasurementUnits {lmPixels, lmLayoutUnits};
  36.  
  37. enum TRelationship {
  38.   lmAsIs      = 0,
  39.   lmPercentOf = 1,
  40.   lmAbove     = 2, lmLeftOf = lmAbove,
  41.   lmBelow     = 3, lmRightOf = lmBelow,
  42.   lmSameAs    = 4,
  43.   lmAbsolute  = 5
  44. };
  45.  
  46. //
  47. // struct TLayoutConstraint
  48. // ~~~~~~ ~~~~~~~~~~~~~~~~~
  49. // Layout constraints are specified as a relationship between an edge/size
  50. // of one window and an edge/size of one of the window's siblings or parent
  51. //
  52. // It is acceptable for a window to have one of its sizes depend on the
  53. // size of the opposite dimension (e.g. width is twice height)
  54. //
  55. // Distances can be specified in either pixels or layout units
  56. //
  57. // A layout unit is defined by dividing the font "em" quad into 8 vertical
  58. // and 8 horizontal segments. we get the font by self-sending WM_GETFONT
  59. // (we use the system font if WM_GETFONT returns 0)
  60. //
  61. // "lmAbove", "lmBelow", "lmLeftOf", and "lmRightOf" are only used with edge
  62. // constraints. They place the window 1 pixel to the indicated side (i.e.
  63. // adjacent to the other window) and then adjust it by "Margin" (e.g. above
  64. // window "A" by 6)
  65. //
  66. // NOTE: "Margin" is either added to ("lmAbove" and "lmLeftOf") or subtracted
  67. //       from("lmBelow" and "lmRightOf") depending on the relationship
  68. //
  69. // "lmSameAs" can be used with either edges or sizes, and it doesn't offset
  70. // by 1 pixel like the above four relationships did. it also uses "Value"
  71. // (e.g. same width as window "A" plus 10)
  72. //
  73. // NOTE: "Value" is always *added*. use a negative number if you want the
  74. //       effect to be subtractive
  75. //
  76. struct TLayoutConstraint {
  77.   TWindow*           RelWin;            // relative window, lmParent for parent
  78.  
  79.   uint               MyEdge       : 4;  // edge or size (width/height)
  80.   TRelationship      Relationship : 4;
  81.   TMeasurementUnits  Units        : 4;
  82.   uint               OtherEdge    : 4;  // edge or size (width/height)
  83.  
  84.   // This union is just for naming convenience
  85.   //
  86.   union {
  87.     int  Margin;   // used for "lmAbove", "lmBelow", "lmLeftOf", "lmRightOf"
  88.     int  Value;    // used for "lmSameAs" and "lmAbsolute"
  89.     int  Percent;  // used for "lmPercentOf"
  90.   };
  91. };
  92.  
  93. //
  94. // struct TEdgeConstraint
  95. // ~~~~~~ ~~~~~~~~~~~~~~~
  96. // Adds member functions for setting edge constraints
  97. //
  98. struct TEdgeConstraint : public TLayoutConstraint {
  99.  
  100.   // For setting arbitrary edge constraints. use it like this:
  101.   //   metrics->X.Set(lmLeft, lmRightOf, lmParent, lmLeft, 10);
  102.   //
  103.   void    Set(TEdge edge,      TRelationship rel, TWindow* otherWin,
  104.               TEdge otherEdge, int value = 0);
  105.  
  106.   // These four member functions can be used to position your window with
  107.   // respective to a sibling window. you specify the sibling window and an
  108.   // optional margin between the two windows
  109.   //
  110.   void    LeftOf(TWindow* sibling, int margin = 0);
  111.   void    RightOf(TWindow* sibling, int margin = 0);
  112.   void    Above(TWindow* sibling, int margin = 0);
  113.   void    Below(TWindow* sibling, int margin = 0);
  114.  
  115.   // These two work on the same edge, e.g. "SameAs(win, lmLeft)" means
  116.   // that your left edge should be the same as the left edge of "otherWin"
  117.   //
  118.   void    SameAs(TWindow* otherWin, TEdge edge);
  119.   void    PercentOf(TWindow* otherWin, TEdge edge, int percent);
  120.  
  121.   // Setting an edge to a fixed value
  122.   //
  123.   void    Absolute(TEdge edge, int value);
  124.  
  125.   // Letting an edge remain as-is
  126.   //
  127.   void    AsIs(TEdge edge);
  128. };
  129.  
  130. //
  131. // struct TEdgeOrSizeConstraint
  132. // ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
  133. struct TEdgeOrSizeConstraint : public TEdgeConstraint {
  134.  
  135.   // Redefine member functions defined by TEdgeConstraint that are hidden by
  136.   // TEdgeOrSizeConstraint because of extra/different params
  137.   //
  138.   void    Absolute(TEdge edge, int value);
  139.   void    PercentOf(TWindow* otherWin, TEdge edge, int percent);
  140.   void    SameAs(TWindow* otherWin, TEdge edge);
  141.   void    AsIs(TEdge edge);
  142.   void    AsIs(TWidthHeight edge);
  143. };
  144.  
  145. struct TEdgeOrWidthConstraint : public TEdgeOrSizeConstraint {
  146.  
  147.   // Redefine member functions defined by TEdgeOrSizeConstraint that are hidden by
  148.   // TEdgeOrWidthConstraint because of extra/different params
  149.   //
  150.   void    Absolute(TEdge edge, int value);
  151.   void    PercentOf(TWindow* otherWin, TEdge edge, int percent);
  152.   void    SameAs(TWindow* otherWin, TEdge edge);
  153.  
  154.   // Setting a width/height to a fixed value
  155.   //
  156.   void    Absolute(int value);
  157.  
  158.   // Percent of another window's width/height (defaults to being the same
  159.   // dimension but could be the opposite dimension, e.g. make my width 50%
  160.   // of my parent's height)
  161.   //
  162.   void    PercentOf(TWindow*     otherWin,
  163.                     int          percent,
  164.                     TWidthHeight otherWidthHeight = lmWidth);
  165.  
  166.   // Same as another window's width/height (defaults to being the same
  167.   // dimension but could be the opposite dimension, e.g. make my width
  168.   // the same as my height)
  169.   //
  170.   void    SameAs(TWindow*     otherWin,
  171.                  TWidthHeight otherWidthHeight = lmWidth,
  172.                  int          value = 0);
  173.  
  174. };
  175.  
  176. struct TEdgeOrHeightConstraint : public TEdgeOrSizeConstraint {
  177.  
  178.   // Redefine member functions defined by TEdgeOrSizeConstraint that are hidden by
  179.   // TEdgeOrHeightConstraint because of extra/different params
  180.   //
  181.   void    Absolute(TEdge edge, int value);
  182.   void    PercentOf(TWindow* otherWin, TEdge edge, int percent);
  183.   void    SameAs(TWindow* otherWin, TEdge edge);
  184.  
  185.   // Setting a width/height to a fixed value
  186.   //
  187.   void    Absolute(int value);
  188.  
  189.   // Percent of another window's width/height (defaults to being the same
  190.   // dimension but could be the opposite dimension, e.g. make my width 50%
  191.   // of my parent's height)
  192.   //
  193.   void    PercentOf(TWindow*     otherWin,
  194.                     int          percent,
  195.                     TWidthHeight otherWidthHeight = lmHeight);
  196.  
  197.   // Same as another window's width/height (defaults to being the same
  198.   // dimension but could be the opposite dimension, e.g. make my width
  199.   // the same as my height)
  200.   //
  201.   void    SameAs(TWindow*     otherWin,
  202.                  TWidthHeight otherWidthHeight = lmHeight,
  203.                  int          value = 0);
  204.  
  205. };
  206.  
  207. // Generic definitions/compiler options (eg. alignment) following the 
  208. // definition of classes
  209. #include <services/posclass.h>
  210.  
  211. #if defined(BI_NAMESPACE)
  212. } // namespace OWL
  213. #endif
  214.  
  215. //----------------------------------------------------------------------------
  216. // Inline implementations
  217.  
  218. //
  219. inline void TEdgeConstraint::Set(TEdge edge, TRelationship rel, TWindow* otherWin,
  220.                                  TEdge otherEdge, int value)
  221. {
  222.   RelWin = otherWin;
  223.   MyEdge = edge;
  224.   Relationship = rel;
  225.   OtherEdge = otherEdge;
  226.   Value = value;
  227. }
  228.  
  229. //
  230. inline void TEdgeConstraint::LeftOf(TWindow* sibling, int margin)
  231. {
  232.   Set(lmRight, lmLeftOf, sibling, lmLeft, margin);
  233. }
  234.  
  235. //
  236. inline void TEdgeConstraint::RightOf(TWindow* sibling, int margin)
  237. {
  238.   Set(lmLeft, lmRightOf, sibling, lmRight, margin);
  239. }
  240.  
  241. //
  242. inline void TEdgeConstraint::Above(TWindow* sibling, int margin)
  243. {
  244.   Set(lmBottom, lmAbove, sibling, lmTop, margin);
  245. }
  246.  
  247. //
  248. inline void TEdgeConstraint::Below(TWindow* sibling, int margin)
  249. {
  250.   Set(lmTop, lmBelow, sibling, lmBottom, margin);
  251. }
  252.  
  253. //
  254. inline void TEdgeConstraint::SameAs(TWindow* otherWin, TEdge edge)
  255. {
  256.   Set(edge, lmSameAs, otherWin, edge, 0);
  257. }
  258.  
  259. //
  260. inline void TEdgeConstraint::PercentOf(TWindow* otherWin, TEdge edge, int percent)
  261. {
  262.   Set(edge, lmPercentOf, otherWin, edge, percent);
  263. }
  264.  
  265. //
  266. inline void TEdgeConstraint::Absolute(TEdge edge, int value)
  267. {
  268.   MyEdge = edge;
  269.   Value = value;
  270.   Relationship = lmAbsolute;
  271. }
  272.  
  273. //
  274. inline void TEdgeConstraint::AsIs(TEdge edge)
  275. {
  276.   MyEdge = edge;
  277.   Relationship = lmAsIs;
  278. }
  279.  
  280. //---
  281.  
  282. //
  283. inline void TEdgeOrSizeConstraint::AsIs(TEdge edge)
  284. {
  285.   TEdgeConstraint::AsIs(edge);
  286. }
  287.  
  288. //
  289. inline void TEdgeOrSizeConstraint::AsIs(TWidthHeight edge)
  290. {
  291.   TEdgeConstraint::AsIs(TEdge(edge));
  292. }
  293.  
  294. //---
  295.  
  296. //
  297. inline void TEdgeOrWidthConstraint::Absolute(TEdge edge, int value)
  298. {
  299.   TEdgeConstraint::Absolute(edge, value);
  300. }
  301.  
  302. //
  303. inline void TEdgeOrWidthConstraint::PercentOf(TWindow* otherWin, TEdge edge, int percent)
  304. {
  305.   TEdgeConstraint::PercentOf(otherWin, edge, percent);
  306. }
  307.  
  308. //
  309. inline void TEdgeOrWidthConstraint::SameAs(TWindow* otherWin, TEdge edge)
  310. {
  311.   TEdgeConstraint::SameAs(otherWin, edge);
  312. }
  313.  
  314. //
  315. inline void TEdgeOrWidthConstraint::Absolute(int value)
  316. {
  317.   MyEdge = lmWidth;
  318.   Value = value;
  319.   Relationship = lmAbsolute;
  320. }
  321.  
  322. //
  323. inline void TEdgeOrWidthConstraint::PercentOf(TWindow* otherWin,
  324.   int percent, TWidthHeight otherWidthHeight)
  325. {
  326.   RelWin = otherWin;
  327.   MyEdge = lmWidth;
  328.   Relationship = lmPercentOf;
  329.   OtherEdge = otherWidthHeight;
  330.   Percent = percent;
  331. }
  332.  
  333. //
  334. inline void TEdgeOrWidthConstraint::SameAs(TWindow* otherWin,
  335.   TWidthHeight otherWidthHeight, int value)
  336. {
  337.   RelWin = otherWin;
  338.   MyEdge = lmWidth;
  339.   Relationship = lmSameAs;
  340.   OtherEdge = otherWidthHeight;
  341.   Value = value;
  342. }
  343.  
  344. //---
  345.  
  346. //
  347. inline void TEdgeOrHeightConstraint::Absolute(TEdge edge, int value)
  348. {
  349.   TEdgeConstraint::Absolute(edge, value);
  350. }
  351.  
  352. //
  353. inline void TEdgeOrHeightConstraint::PercentOf(TWindow* otherWin, TEdge edge, int percent)
  354. {
  355.   TEdgeConstraint::PercentOf(otherWin, edge, percent);
  356. }
  357.  
  358. //
  359. inline void TEdgeOrHeightConstraint::SameAs(TWindow* otherWin, TEdge edge)
  360. {
  361.   TEdgeConstraint::SameAs(otherWin, edge);
  362. }
  363.  
  364. //
  365. inline void TEdgeOrHeightConstraint::Absolute(int value)
  366. {
  367.   MyEdge = lmHeight;
  368.   Value = value;
  369.   Relationship = lmAbsolute;
  370. }
  371.  
  372. //
  373. inline void TEdgeOrHeightConstraint::PercentOf(TWindow* otherWin,
  374.   int percent, TWidthHeight otherWidthHeight)
  375. {
  376.   RelWin = otherWin;
  377.   MyEdge = lmHeight;
  378.   Relationship = lmPercentOf;
  379.   OtherEdge = otherWidthHeight;
  380.   Percent = percent;
  381. }
  382.  
  383. //
  384. inline void TEdgeOrHeightConstraint::SameAs(TWindow* otherWin,
  385.   TWidthHeight otherWidthHeight, int value)
  386. {
  387.   RelWin = otherWin;
  388.   MyEdge = lmHeight;
  389.   Relationship = lmSameAs;
  390.   OtherEdge = otherWidthHeight;
  391.   Value = value;
  392. }
  393.  
  394. #endif  // OWL_LAYOUTCO_H
  395.